import request from '@/config/axios'
import { getRefreshToken } from '@/utils/auth'

export interface SmsCodeVO {
  mobile: string
  scene: number
}

export interface SmsLoginVO {
  mobile: string
  code: string
}

// 登录
// export const login = (data: UserLoginVO) => {
//   return request.post({ url: '/system/auth/login', data })
// }

// 刷新访问令牌
export const refreshToken = () => {
  return request.post({
    url:
      '/system/auth/refresh-token?refreshToken=' +
      getRefreshToken()
  })
}

// 使用租户名，获得租户编号
export const getTenantIdByName = (name: string) => {
  return request.get({
    url: '/system/tenant/get-id-by-name?name=' + name
  })
}

// 使用用户名，获得租户编号
export const getTenantIdByUserName = (userName: string) => {
  return request.get({
    url:
      '/system/tenant/get-id-by-username?userName=' +
      userName
  })
}

// 登出
export const loginOut = () => {
  return request.post({ url: '/system/auth/logout' })
}

// 获取用户权限信息
export const getInfo = () => {
  return request.get({
    url: '/system/auth/get-permission-info'
  })
}

// 路由
export const getAsyncRoutes = () => {
  return request.get({ url: '/system/auth/list-menus' })
}

// 短信验证码登录
export const smsLogin = (data: SmsLoginVO) => {
  return request.post({
    url: '/system/auth/sms-login',
    data
  })
}

// 社交授权的跳转
export const socialAuthRedirect = (
  type: number,
  redirectUri: string
) => {
  return request.get({
    url:
      '/system/auth/social-auth-redirect?type=' +
      type +
      '&redirectUri=' +
      redirectUri
  })
}
// 获取验证图片以及 token
export const getCode = (data) => {
  return request.postOriginal({
    url: 'system/captcha/get',
    data
  })
}

// 滑动或者点选验证
export const reqCheck = (data) => {
  return request.postOriginal({
    url: 'system/captcha/check',
    data
  })
}

export const getTenantIdByDomain = async (params) => {
  return await request.get({
    url: '/system/tenant/getTenantIdByDomain',
    params
  })
}

export const getUserByUsername = async (params) => {
  return await request.get({
    url: '/system/auth/getUserByUsername',
    params
  })
}

export const forgetPassword = async (data) => {
  return await request.put({
    url: '/system/user/profile/forgetPassword',
    data
  })
}

//----------------新接口----------------------------

// 校验账号是否注册
export const validLogin = async (data) => {
  return await request.postOriginal({
    url: '/system/auth/validLogin',
    data
  })
}

// 登录
export const login = async (data) => {
  return await request.postOriginal({
    url: '/system/auth/loginV2',
    data
  })
}

// 查看租户
export const getTenantListByAccount = async (params) => {
  return await request.get({
    url: '/system/tenant/getTenantListByAccount',
    params
  })
}

//获取登录验证码
export const sendSmsCode = (data: SmsCodeVO) => {
  return request.post({
    url: '/system/auth/send-sms-code',
    data
  })
}

//获取登录验证码
export const register = (data) => {
  return request.postDYXT({
    url: '/cargo-owner-approval/register',
    data
  })
}

// 货主企业校验
export const validCargoOwnerApprovalName = (params) => {
  return request.getDYXT({
    url: '/cargo-owner-approval/validCargoOwnerApprovalName',
    params
  })
}

// 货主账号校验
export const validUsername = (params) => {
  return request.getDYXT({
    url: '/cargo-owner-approval/validUsername',
    params
  })
}

// 货主账号校验
export const haveAuthorize = (params) => {
  return request.getDYXT({
    url: '/account-authorize/have-authorize',
    params
  })
}

// 货主账号校验
export const authorizeByUserId = (data) => {
  return request.putDYXT({
    url: '/account-authorize/authorizeByUserId',
    data
  })
}

// 货主账号校验
export const getBasicUserInfoById = (params) => {
  return request.getDYXT({
    url: '/account-authorize/getBasicUserInfoById',
    params
  })
}

// 注册并登录
export const registerAndLogin = (data) => {
  return request.postDYXT({
    url: '/cargo-owner-approval/register-and-login',
    data
  })
}

// 切换租户
export const loginSwitchMobile = (data) => {
  return request.post({
    url: '/system/auth/loginSwitchMobile',
    data
  })
}

// 切换租户
export const switchDispatchServer = (params) => {
  return request.get({
    url: '/system/auth/switch-dispatch-server',
    params
  })
}

// 埋点新增接口
export const createPageAccessLog = (data) => {
  return request.post({
    url: '/system/page-access-log/create',
    data
  })
}

// 埋点修改接口
export const updatePageAccessLog = (data) => {
  return request.put({
    url: '/system/page-access-log/update',
    data
  })
}
